# tools
CC := gcc
RM := rm -f

# flags
CFLAGS := -ggdb
LDFLAGS :=
LDLIBS :=

# sources
sources := target1.c target2.c target3.c target4.c target5.c \
           target6.c target7.c target-ec tmalloc.c
targets := target1 target2 target3 target4 target5 target6 target7 target-ec

# gmake magic
.PHONY: default all clean

#targets
default: setup
all: $(targets)

clean:
	$(RM) $(targets) $(sources:.c=.o)
	rm -rf ./bin

moveToBin: all
	rm -rf ./bin
	mkdir bin
	mv $(targets) ./bin
	mv ./*.o ./bin
	cp ./*.c ./bin
	cp ./*.h ./bin
	chown user:user ./bin/*
	chown user:user ./bin/

setup: moveToBin
	cp ./bin/* /tmp
	cp -r ./* /tmp
	rm -rf /tmp/bin
	chown root:root /tmp/target? ; chmod 4755 /tmp/target? ; chmod a+r target?.c

# special make process for eip target
target3:    CFLAGS += -fomit-frame-pointer -O2

#dependencies
target5: tmalloc.o
tmalloc.o target5.o: tmalloc.h
